package com.dykj.fireFighting.web.occupiedvideo;

import java.util.*;


import com.dykj.fireFighting.api.socialUnit.occupiedvideo.dto.OccupiedVideoDto;
import com.dykj.fireFighting.api.socialUnit.occupiedvideo.entity.OccupiedVideo;
import com.dykj.fireFighting.api.socialUnit.occupiedvideo.service.IOccupiedVideoService;
import com.dykj.fireFighting.api.socialUnit.occupiedvideo.vo.OccupiedVideoPlayVo;
import com.dykj.fireFighting.common.core.annotation.AutoLog;
import com.dykj.fireFighting.common.core.api.CommonResult;
import com.dykj.fireFighting.common.core.dto.CommonDto;
import com.dykj.fireFighting.common.core.utils.UUIDUtils;
import com.dykj.fireFighting.common.core.vo.LoginUserVo;
import com.dykj.fireFighting.common.core.vo.PageVo;
import com.dykj.fireFighting.web.base.shiro.ShiroUtil;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;



import javax.validation.Valid;



/**
 * 救援场地和消防车通道占用情况接口
 *
 * @Author zly
 * @Date  2021-07-20 10:17:37
 */
@Slf4j
@Api(value = "救援场地和消防车通道占用情况接口", tags = {"救援场地和消防车通道占用情况接口"})
@RestController
@RequestMapping("occupiedVideo")
public class OccupiedVideoController {

    @DubboReference
    private IOccupiedVideoService occupiedVideoService;

    /**
     * 救援场地和消防车通道占用情况列表
     *
     * @return
     */
    @AutoLog(value = "救援场地和消防车通道占用情况-分页列表查询")
    @ApiOperation(value = "救援场地和消防车通道占用情况分页列表", notes = "救援场地和消防车通道占用情况分页列表")
    @GetMapping("/list")
    //@RequiresPermissions("unit/occupiedVideo/list")
    public CommonResult<PageVo<OccupiedVideo>> treeGrid(OccupiedVideoDto occupiedVideoDto) {
        LoginUserVo user = ShiroUtil.getUser();
        Long enterpriseId = user.getEnterpriseId();
        occupiedVideoDto.setUnitId(Long.toString(enterpriseId));
        PageVo<OccupiedVideo> page = occupiedVideoService.queryList(occupiedVideoDto);
        return CommonResult.success(page);
    }

    /**
     * 获取救援场地和消防车通道占用情况信息
     */
    @AutoLog(value = "救援场地和消防车通道占用情况-获取救援场地和消防车通道占用情况信息")
    @ApiOperation(value = "获取救援场地和消防车通道占用情况信息", notes = "获取救援场地和消防车通道占用情况信息")
    @ApiImplicitParam(paramType = "path", name = "id", value = "主键ID", dataType = "String", required = true)
    @GetMapping("/info/{id}")
    //@RequiresPermissions("occupiedVideo/info")
    public CommonResult<OccupiedVideo> info(@PathVariable("id") String id){
        OccupiedVideo occupiedVideo = occupiedVideoService.getById(id);
        return CommonResult.success(occupiedVideo);
    }

    /**
     * 保存救援场地和消防车通道占用情况信息
     */
    @AutoLog(value = "救援场地和消防车通道占用情况-保存救援场地和消防车通道占用情况信息")
    @ApiOperation(value = "保存救援场地和消防车通道占用情况信息", notes = "保存救援场地和消防车通道占用情况信息")
    @PostMapping("/save")
    //@RequiresPermissions("occupiedVideo/save")
    public CommonResult save(@Valid @RequestBody OccupiedVideo occupiedVideo) {
        try {
            LoginUserVo loginUserVo = ShiroUtil.getUser();
            occupiedVideo.setId(UUIDUtils.get32UUID());
            occupiedVideo.setUnitId(loginUserVo.getEnterpriseId().toString());
            occupiedVideo.setCreateTime(new Date());
            occupiedVideo.setCreateBy(loginUserVo.getId().toString());
                occupiedVideoService.save(occupiedVideo);
            return CommonResult.success("添加成功");
        } catch (Exception e) {
            log.error(e.getMessage());
            return CommonResult.failed("添加失败，请联系管理员");
        }
    }

    /**
     * 修改救援场地和消防车通道占用情况信息
     */
    @AutoLog(value = "救援场地和消防车通道占用情况-修改救援场地和消防车通道占用情况信息")
    @ApiOperation(value = "修改救援场地和消防车通道占用情况信息", notes = "修改救援场地和消防车通道占用情况信息")
    @PostMapping("/update")
   // @RequiresPermissions("occupiedVideo/update")
    public CommonResult update(@Valid @RequestBody OccupiedVideo occupiedVideo) {
        try {
            LoginUserVo loginUserVo = ShiroUtil.getUser();
            occupiedVideo.setUpdateBy(loginUserVo.getId().toString());
            occupiedVideo.setUpdateTime(new Date());
                occupiedVideoService.updateById(occupiedVideo);
            return CommonResult.success("修改成功");
        } catch (Exception e) {
            log.error(e.getMessage());
            return CommonResult.failed("添加失败，请联系管理员");
        }
    }

    /**
     * 删除救援场地和消防车通道占用情况信息
     */
    @AutoLog(value = "救援场地和消防车通道占用情况-删除救援场地和消防车通道占用情况信息")
    @ApiOperation(value = "删除救援场地和消防车通道占用情况信息", notes = "删除救援场地和消防车通道占用情况信息")
    @ApiImplicitParam(paramType = "query", name = "ids", value = "ID数组", dataType = "String", required = true, allowMultiple = true)
    @PostMapping("/delete")
   // @RequiresPermissions("occupiedVideo/delete")
    public CommonResult delete(@RequestBody String[]ids) {
        try {
                occupiedVideoService.removeByIds(Arrays.asList(ids));
            return CommonResult.success("删除成功");
        } catch (Exception e) {
            log.error(e.getMessage());
            return CommonResult.failed("添加失败，请联系管理员");
        }
    }

    /**
     * 视频播放
     *
     * @param id
     * @return
     */
    @AutoLog(value = "视频播放")
    @ApiOperation(value = "视频播放", notes = "视频播放")
    @ApiImplicitParam(paramType = "path", name = "id", value = "主键ID", dataType = "String", required = true)
    @GetMapping("/play/{id}")
    //@RequiresPermissions("device/video/paly")
    public CommonResult<OccupiedVideoPlayVo> play(@PathVariable("id") String id) {
       OccupiedVideoPlayVo videoPlayVo = occupiedVideoService.videoPlay(id);
        return CommonResult.success(videoPlayVo);
    }

}
